package gui.view;

import gui.controller.MaxSolutionsListener;

import java.beans.PropertyChangeListener;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import solverLogic.Solver;

public class MaxSolutionsChoiceBox extends JSpinner {

	private static final long serialVersionUID = -9207385045939180819L;
	private MaxSolutionsListener listener;

	public MaxSolutionsChoiceBox() {
		super(new SpinnerNumberModel(Integer.MAX_VALUE, 1, Solver
				.getMaxSolutions(), 1));
	}

	@Override
	public void addPropertyChangeListener(final PropertyChangeListener listener) {
		super.addPropertyChangeListener(listener);
		this.getListener().addPropertyChangeListener(listener);
	}

	private MaxSolutionsListener getListener() {
		if (this.listener == null) {
			this.listener = new MaxSolutionsListener(this);
			this.addChangeListener(this.listener);
		}
		return this.listener;
	}

	@Override
	public void removePropertyChangeListener(
			final PropertyChangeListener listener) {
		super.removePropertyChangeListener(listener);
		this.getListener().removePropertyChangeListener(listener);
	}
}
